package com.ruoyi.web.core.config;

import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.service.AiServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;


@Configuration
public class LLMOllamaConfig {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${langchain4j.ollama.chat-model.model-name}")
    private String modelName;
    @Value("${langchain4j.ollama.chat-model.base-url}")
    private String baseUrl;

    // 注意这里的方法名字不要重复
    @Bean
    public OllamaChatModel ollamaChatModel() {

        return OllamaChatModel.builder()
                .modelName(modelName)
                .baseUrl(baseUrl)
                .timeout(Duration.ofSeconds(30))
                .temperature(0d)
                .build();

    }

    @Bean
    public OllamaChatAssistant ollamaChatAssistant() {
        return AiServices.builder(OllamaChatAssistant.class)
                .chatLanguageModel(ollamaChatModel())
                .build();
    }
}
